<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - qgetopt test coverage - object/optionManager/optSwitch.h</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../../index.html">directory</a> - <a href="index.html">object/optionManager</a> - optSwitch.h</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>qgetopt test coverage</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-08-26</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">16</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">93.8 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">15</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : #ifndef OPT_SWITCH_H
<span class="lineNum">       2 </span>                : #define OPT_SWITCH_H
<span class="lineNum">       3 </span>                : 
<span class="lineNum">       4 </span>                : /*! \ingroup qgetopt
<span class="lineNum">       5 </span>                :     \brief This enum type defines the switch style.
<span class="lineNum">       6 </span>                : 
<span class="lineNum">       7 </span>                :     \b continueRunning means that the program will continue running after processing the switch.
<span class="lineNum">       8 </span>                : 
<span class="lineNum">       9 </span>                :     \b immediateStop means that the program will stop once the switch has been processed.
<span class="lineNum">      10 </span>                :  */
<span class="lineNum">      11 </span>                : enum switchStyle{continueRunning, immediateStop};
<span class="lineNum">      12 </span>                : 
<span class="lineNum">      13 </span>                : #include &lt;QtCore&gt;
<span class="lineNum">      14 </span>                : 
<span class="lineNum">      15 </span>                : #include &quot;optManager.h&quot;
<span class="lineNum">      16 </span>                : #include &quot;optArgument.h&quot;
<span class="lineNum">      17 </span>                : 
<span class="lineNum">      18 </span>                : /*! \ingroup qgetopt
<span class="lineNum">      19 </span>                :     \brief The OptSwitch class holds details of a switch.
<span class="lineNum">      20 </span>                : 
<span class="lineNum">      21 </span>                :     This class is a \em private class and instances may only be created by the OptManager object which is a friend class.
<span class="lineNum">      22 </span>                : 
<span class="lineNum">      23 </span>                :     A switch will have a \em fullName, it may also have an \em abbrev which must be a single letter or a single number.
<span class="lineNum">      24 </span>                :     A switch may have any number of arguments, either mandatory or optional. All optional arguments
<span class="lineNum">      25 </span>                :     are contained in square brackets. A switch may also be associated with an \em actionMethod, which will be a
<span class="lineNum">      26 </span>                :     pointer to a method and will be run during the OptManager::pharse() phase of the program.
<span class="lineNum">      27 </span>                :     In addition it may have an \em exitMethod, which is a pointer to a method and will be run during the
<span class="lineNum">      28 </span>                :     OptManager::close() phase. Finaly the switch will have a \em style flag which may be set to either
<span class="lineNum">      29 </span>                :     \em continueRunning or \em immediateStop, if it is set to \em immediateStop then the application
<span class="lineNum">      30 </span>                :     will stop once the \em actionMethod has been executed.
<span class="lineNum">      31 </span>                : 
<span class="lineNum">      32 </span>                :     A switch can be created by calling the OptManager::addSwitch() method.
<span class="lineNum">      33 </span>                :     This method returns a pointer to the instance of the switch object which allows any of the public methods to be called.
<span class="lineNum">      34 </span>                :     Thus by calling addDescription() a description can be added to a switch which will be displayed in the help screen.
<span class="lineNum">      35 </span>                : 
<span class="lineNum">      36 </span>                :  * \attention This program is free software; you can redistribute it and/or modify
<span class="lineNum">      37 </span>                :  * it under the terms of the GNU General Public License as published by
<span class="lineNum">      38 </span>                :  * the Free Software Foundation; either version 2 of the License, or
<span class="lineNum">      39 </span>                :  * (at your option) any later version.
<span class="lineNum">      40 </span>                :  *
<span class="lineNum">      41 </span>                :  * \attention This program is distributed in the hope that it will be useful,
<span class="lineNum">      42 </span>                :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
<span class="lineNum">      43 </span>                :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
<span class="lineNum">      44 </span>                :  * GNU General Public License for more details.
<span class="lineNum">      45 </span>                :  *
<span class="lineNum">      46 </span>                :  * \attention You should have received a copy of the GNU General Public License
<span class="lineNum">      47 </span>                :  * along with this program; if not, write to the
<span class="lineNum">      48 </span>                :  * Free Software Foundation, Inc.,
<span class="lineNum">      49 </span>                :  * 59 Temple Place - Suite 330, Boston, MA  02111-1307  USA
<span class="lineNum">      50 </span>                :  *
<span class="lineNum">      51 </span>                :    \author    Graeme
<span class="lineNum">      52 </span>                :    \date Copyright (C) 2008-9  Graeme Foster
<span class="lineNum">      53 </span>                :  */
<span class="lineNum">      54 </span>                : class OptSwitch
<span class="lineNum">      55 </span>                : {
<span class="lineNum">      56 </span>                :    //! OptSwitch is a private class with all interaction through OptManager
<span class="lineNum">      57 </span>                :    /*! The OptManager makes available the following methods:
<span class="lineNum">      58 </span>                :      &lt;table&gt;&lt;tr&gt;&lt;td&gt;addSwitch()&lt;/td&gt;&lt;td&gt;to create a switch&lt;/td&gt;&lt;/tr&gt;
<span class="lineNum">      59 </span>                :        &lt;tr&gt;&lt;td&gt;getSwitchDetails()&lt;/td&gt;&lt;td&gt;which returns the arguments as a QStringList that were provided for a particular switch,
<span class="lineNum">      60 </span>                :        if the switch was not provided, or no arguments were given then an empty QStringList is returned.&lt;/td&gt;&lt;/tr&gt;
<span class="lineNum">      61 </span>                :      &lt;/table&gt;
<span class="lineNum">      62 </span>                :    */
<span class="lineNum">      63 </span>                :    friend class OptManager;
<span class="lineNum">      64 </span>                :    /*! This is an overloaded member function, provided for convenience. */
<span class="lineNum">      65 </span>                :    friend QTextStream &amp; operator&lt;&lt; ( QTextStream &amp; stream, const OptSwitch &amp; os );
<span class="lineNum">      66 </span>                : 
<span class="lineNum">      67 </span>                :    private:
<span class="lineNum">      68 </span>                :       //! \internal The short name of the switch, this is a single letter
<span class="lineNum">      69 </span>                :       QChar _shortName;
<span class="lineNum">      70 </span>                :       //! \internal The long name of the switch
<span class="lineNum">      71 </span>                :       QString _longName;
<span class="lineNum">      72 </span>                :       //! \internal The detailed description of the switch
<span class="lineNum">      73 </span>                :       QString _description;
<span class="lineNum">      74 </span>                :       //! \internal The list of arguments that are required
<span class="lineNum">      75 </span>                :       QList &lt;OptArgument *&gt; _mandatoryArgList;
<span class="lineNum">      76 </span>                :       //! \internal The list of arguments that may also be provided
<span class="lineNum">      77 </span>                :       QList &lt;OptArgument *&gt; _optionalArgList;
<span class="lineNum">      78 </span>                :       //! \internal The list of arguments that have actually been provided
<span class="lineNum">      79 </span>                :       QStringList _actualArgList;
<span class="lineNum">      80 </span>                :       //! \internal The function that will be executed at start-up if the switch has been selected
<span class="lineNum">      81 </span>                :       ActionFuncPtr _actionFn;
<span class="lineNum">      82 </span>                :       //! \internal The function that will be executed at wrap-up if the switch has been selected
<span class="lineNum">      83 </span>                :       CloseFuncPtr _closeFn;
<span class="lineNum">      84 </span>                :       //! \internal Flag to indicate it the program should abort after running its own functions if the switch is provided
<span class="lineNum">      85 </span>                :       switchStyle _style;
<span class="lineNum">      86 </span>                :    public:
<span class="lineNum">      87 </span>                :       //!  Add a detailed description to the switch
<span class="lineNum">      88 </span>                :       /*! This description will be displayed in the help file.
<span class="lineNum">      89 </span>                :           The switch instance is returned from addSwitch() for example:
<span class="lineNum">      90 </span>                :           \code
<span class="lineNum">      91 </span>                :              QString detail;
<span class="lineNum">      92 </span>                :              OptManager * om = OptManager::getOptMgr(ProgName);
<span class="lineNum">      93 </span>                :              detail = QObject::tr(&quot;This will backupthe log file before any changes are made to it.&quot;);
<span class="lineNum">      94 </span>                :              om-&gt;addSwitch(&quot;back-up&quot;,backup, 'b', &quot;FILE&quot;)-&gt;addDescription(detail);
<span class="lineNum">      95 </span>                :           \endcode
<span class="lineNum">      96 </span>                :       */
<span class="lineNum">      97 </span><span class="lineCov">            113 :       void addDescription(QString detail){_description=detail;}</span>
<span class="lineNum">      98 </span>                :       //! return the details of a specific arguments received.
<span class="lineNum">      99 </span>                :       /*! The argument if it exists will be returned. */
<span class="lineNum">     100 </span><span class="lineCov">              2 :       inline QString getArg(int cnt) const</span>
<span class="lineNum">     101 </span>                :       {
<span class="lineNum">     102 </span><span class="lineCov">              2 :          if ((cnt &gt;= 0) &amp;&amp; (cnt &lt; actualArgCnt()))</span>
<span class="lineNum">     103 </span><span class="lineCov">              2 :             return _actualArgList.at(cnt);</span>
<span class="lineNum">     104 </span>                :          else
<span class="lineNum">     105 </span><span class="lineNoCov">              0 :             return QString();</span>
<span class="lineNum">     106 </span>                :       }
<span class="lineNum">     107 </span>                :       //! return the details of arguments received.
<span class="lineNum">     108 </span>                :       /*! The arguments are returned as a string list. */
<span class="lineNum">     109 </span><span class="lineCov">             11 :       QStringList argList() const {return _actualArgList;}</span>
<span class="lineNum">     110 </span><span class="lineCov">             30 :       int actualArgCnt()const {return _actualArgList.size();}</span>
<span class="lineNum">     111 </span>                :    private:
<span class="lineNum">     112 </span>                :       //! \internal Private constructor instances will only be created by the friend class OptManager
<span class="lineNum">     113 </span>                :       OptSwitch(QChar abbrev
<span class="lineNum">     114 </span>                :                ,QString fullName
<span class="lineNum">     115 </span>                :                ,QString args
<span class="lineNum">     116 </span>                :                ,ActionFuncPtr actionMethod
<span class="lineNum">     117 </span>                :                ,CloseFuncPtr exitMethod
<span class="lineNum">     118 </span>                :                ,switchStyle style=continueRunning
<span class="lineNum">     119 </span>                :                );
<span class="lineNum">     120 </span>                :       //! \internal Private copy constructor for singleton class
<span class="lineNum">     121 </span>                :       OptSwitch(const OptSwitch&amp;);
<span class="lineNum">     122 </span>                :       //! \internal Return the short switch name
<span class="lineNum">     123 </span><span class="lineCov">            286 :       QChar abbrev(){return _shortName;}</span>
<span class="lineNum">     124 </span>                :       //! \internal Return the long switch name
<span class="lineNum">     125 </span><span class="lineCov">             36 :       QString name(){return _longName;}</span>
<span class="lineNum">     126 </span>                :       //! \internal Add the argument to the list of arguments provided
<span class="lineNum">     127 </span><span class="lineCov">             12 :       void addActualArg(QString arg){_actualArgList.append(arg);}</span>
<span class="lineNum">     128 </span>                :       //! \internal Return the number of mandaroty arguments
<span class="lineNum">     129 </span><span class="lineCov">             54 :       int mArgCnt(){return _mandatoryArgList.size();}</span>
<span class="lineNum">     130 </span>                :       //! \internal Return the number of optional arguments
<span class="lineNum">     131 </span><span class="lineCov">             28 :       int oArgCnt(){return _optionalArgList.size();}</span>
<span class="lineNum">     132 </span>                :       //! \internal Return the total number of arguments
<span class="lineNum">     133 </span><span class="lineCov">             28 :       int argCnt(){return mArgCnt()+oArgCnt();}</span>
<span class="lineNum">     134 </span>                :       //! \internal Return the true if this is a conclude switch
<span class="lineNum">     135 </span><span class="lineCov">             44 :       bool finishProcessing(){return _style;}</span>
<span class="lineNum">     136 </span>                :       //! \internal Execute the switches action method
<span class="lineNum">     137 </span><span class="lineCov">             15 :       void execute(){if (_actionFn)_actionFn(this);}</span>
<span class="lineNum">     138 </span>                :       //! \internal Execute the switches close method
<span class="lineNum">     139 </span><span class="lineCov">             14 :       void close(){if (_closeFn) _closeFn();}</span>
<span class="lineNum">     140 </span>                :       //! \internal Return brief details of the switch, its name and the arguments
<span class="lineNum">     141 </span>                :       QString brief();
<span class="lineNum">     142 </span>                :       //! \internal Return the argument list for the switch
<span class="lineNum">     143 </span>                :       QString fullArgList();
<span class="lineNum">     144 </span>                :       //! \internal Return the details of the switch
<span class="lineNum">     145 </span>                :       QString help();
<span class="lineNum">     146 </span>                :       //! \internal Return the details that have been provided, essentially the actual arguments
<span class="lineNum">     147 </span>                :       QString dump();
<span class="lineNum">     148 </span>                :       //! \internal Format the string to be no more than 80 character wide
<span class="lineNum">     149 </span>                :       QString format80(const QString &amp; msg);
<span class="lineNum">     150 </span>                : };
<span class="lineNum">     151 </span>                : 
<span class="lineNum">     152 </span>                : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
